import { defineStore } from "pinia"
import { getEntireRoles, getEntireDepartments} from '@/service/main/main'

interface IMainState {
  entireRoles: any[]
  entireDepartments: any[]
}

const useMainStore  = defineStore('main', {
  state: (): IMainState => ({
    entireRoles: [],
    entireDepartments: []
  }),
  actions: {
    /**
     * 在登陆成功的时候发起请求 部门 角色
     */
    async fetchEntireDataAction() {
      const rolesResult = await getEntireRoles()
      const departmentsResult = await getEntireDepartments()
      // console.log(rolesResult, departmentsResult)

      //保存数据
      this.entireRoles = rolesResult.data.list
      this.entireDepartments = departmentsResult.data.list
    }
  }
})


export default useMainStore